require "socket"
require "xml_parser"

class TempController < ApplicationController
	layout "standard-layout"
	def index
		list
		render :action => 'list'
	end
	def list
		@temp = nil
		begin
			sock = TCPSocket.new('localhost', 12346)
			sock.puts("<list_temp/>")

			recv = ""
			node = nil
			while node.nil?
				begin
					timeout(10) do
						recv += sock.recvfrom(1024).join
					end
					tmp = recv
					parser = XmlParser.new(tmp)
					node = parser.parse()
				rescue TimeError
					return
				rescue
					node = nil
				end
			end
			sock.close()
			@temp = node["value"]
		rescue
		end
	end
end
